package com.prj.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

import cn.hutool.core.io.FileUtil;

public class PdfToExcel {
	
	public static void main(String[] args) throws Exception{
//		PDDocument document = PDDocument.load(new File("C:\\Users\\keven\\Desktop\\入学\\2025年白云区积分入学资格名单.pdf"));
//		PDFTextStripper pdfStripper = new PDFTextStripper();
//		pdfStripper.setSortByPosition(true);
//		String text = pdfStripper.getText(document);
//		FileUtil.writeUtf8String(text, "C:\\Users\\keven\\Desktop\\资格名单.txt");
		
		List<String> lines = FileUtil.readLines("C:\\Users\\keven\\Desktop\\资格名单.txt", "UTF-8");
		List<String> newLine = new ArrayList<String>();
		int col = 0;
		for(int i=0; i<lines.size();) {
			String str = lines.get(i);
			if(str.startsWith("1") && col == 0) {
				col = 2;
			}
			if(col == 2) {
				 if(str.matches("^[0-9]+.*")) {
					 newLine.add(str);
				 }else {
					 if(str.contains("*")) {
						 if(str.startsWith("劳怡婷") || str.startsWith("吴一亿") || str.startsWith("胡至纯")) {
							 String mid = lines.get(i+1);
							 String bottom = lines.get(i+2);
							 
							 String[] split = mid.split(" ");
							 String parent = "";
							 String point = "";
							 for(int j = 0; j < split.length;j++) {
								if(j < 3) {
									parent += split[j]+" ";
								}
								if(j == 5) {
									point = split[j];
								}
							 }
							 
							 
							 newLine.add(parent+str.substring(0, str.lastIndexOf(" "))+" " + point + str.substring(str.lastIndexOf(" ")));
							 newLine.add(mid);
							 newLine.add(parent+bottom.substring(0, bottom.lastIndexOf(" "))+" " + point + bottom.substring(bottom.lastIndexOf(" ")));
							 i = i+2;
							 System.out.println(str);
							 System.out.println(mid);
							 System.out.println(bottom);
						 }else {
							 String mid = lines.get(i+1);
							 String bottom = lines.get(i+2);
							 String parent = mid.substring(0, mid.lastIndexOf(" "));
							 String point = mid.substring(mid.lastIndexOf(" ")+1);
							 newLine.add(parent+" "+str.substring(0, str.lastIndexOf(" "))+" " + point+ str.substring(str.lastIndexOf(" ")));
							 newLine.add(parent+" "+bottom.substring(0, bottom.lastIndexOf(" "))+" " + point+ bottom.substring(bottom.lastIndexOf(" ")));
							 i = i+2;
						 }
					 }
				 }
			}
			i = i+1;
		}
		FileUtil.writeLines(newLine, "C:\\Users\\keven\\Desktop\\result.txt", "UTF-8");
		System.out.println("finished");
		
//		String str = "208 劳业波 440823****1417 劳泓杰 440823****1438 311 小学一年级";
//		String[] split = str.split(" ");
//		String parent = "";
//		String point = "";
//		for(int i = 0; i < split.length;i++) {
//			if(i < 3) {
//				parent += split[i]+" ";
//			}
//			if(i == 5) {
//				point = split[i];
//			}
//		}
//		System.out.println(parent);
//		System.out.println(point);
		
		
		
		
		
	}

	

}
